/**
 * field_radio
 */
layui.define(['YunjField','form'], function (exports) {

    let YunjField = layui.YunjField;
    let form = layui.form;

    class YunjRadio extends YunjField {

        constructor(options={}) {
            super(options);
        }

        defineExtraArgs(){
            let that = this;
            return {
                options:[],
                disabled:false
            };
        }

        layoutControl() {
            let that = this;
            let controlHtml = '';
            let options = that.args.options;
            for (let k in options) {
                controlHtml += `<input type="radio" name="${that.id}" title="${options[k]}" value="${k}" lay-filter="${that.id}" ${that.args.disabled ? 'disabled' : ''}>`;
            }
            return `<div class="layui-input-inline yunj-input-inline yunj-input-pane">${controlHtml}</div>`;
        }

        setValue(val=''){
            let that=this;
            that.fieldBoxEl.find(`input:radio[name=${that.id}]`).prop('checked', false);
            if(val) that.fieldBoxEl.find(`input:radio[name=${that.id}][value=${val}]`).prop('checked', true);
            form.render('radio', that.tabFormFilter);
        }

        getValue(){
            let that=this;
            return that.fieldBoxEl.find(`input:radio[name=${that.id}]:checked`).val();
        }

        renderDone(){
            let that = this;
            form.render('radio', that.tabFormFilter);
        }

    }

    exports('field_radio', YunjRadio);
});